package com.ordering.action.user;

import java.util.ArrayList;
import java.util.List;

import com.ordering.action.BaseAction;
import com.ordering.constant.ResultResponse;
import com.ordering.entity.Page;
import com.ordering.entity.Product;
import com.ordering.service.product.ProductService;
import com.ordering.service.product.impl.ProductServiceImpl;

public class UserIndexAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	ProductService productService = new ProductServiceImpl();
	
	private Product product;
    
	private int page = 1;
	
	private long totalRecord = 0;
	
	private List<Product> resultList;
	
	public String list(){
        try
        {
        	ResultResponse re = new ResultResponse();
        	re = productService.count(product);
        	totalRecord = (Long)re.getResult();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return FAIL;
        }
        return "list";
    }
	
	public String page(){
        try
        {
        	ResultResponse re = productService.get4page(product, new Page(page,PAGE_SIZE));
        	resultList = (ArrayList<Product>)re.getResult();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return FAIL;
        }
        
        return "page";
    }

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public long getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(long totalRecord) {
		this.totalRecord = totalRecord;
	}

	public List<Product> getResultList() {
		return resultList;
	}

	public void setResultList(List<Product> resultList) {
		this.resultList = resultList;
	}


	
}
